package com.ruoyi.project.zerocarbon.service.impl;

import com.ruoyi.common.utils.DateUtils;
import com.ruoyi.project.zerocarbon.domain.DeclareReporter;
import com.ruoyi.project.zerocarbon.mapper.DeclareReporterMapper;
import com.ruoyi.project.zerocarbon.service.IDeclareReporterService;
import org.apache.commons.collections.CollectionUtils;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * 【请填写功能名称】Service业务层处理
 * 
 * @author ruoyi
 * @date 2021-07-25
 */
@Service
public class DeclareReporterServiceImpl implements IDeclareReporterService 
{
    @Autowired
    private DeclareReporterMapper declareReporterMapper;

    /**
     * 查询【请填写功能名称】
     * 
     * @param id 【请填写功能名称】ID
     * @return 【请填写功能名称】
     */
    @Override
    public DeclareReporter selectDeclareReporterById(Long id)
    {
        return declareReporterMapper.selectDeclareReporterById(id);
    }

    @Override
    public DeclareReporter selectDeclareReporterByDeclarationId(Long declarationId) {
        return declareReporterMapper.selectDeclareReporterByDeclarationId(declarationId);
    }

    /**
     * 查询【请填写功能名称】列表
     * 
     * @param declareReporter 【请填写功能名称】
     * @return 【请填写功能名称】
     */
    @Override
    public List<DeclareReporter> selectDeclareReporterList(DeclareReporter declareReporter)
    {
        return declareReporterMapper.selectDeclareReporterList(declareReporter);
    }

    /**
     * 新增【请填写功能名称】
     * 
     * @param declareReporter 【请填写功能名称】
     * @return 结果
     */
    @Override
    public int insertDeclareReporter(DeclareReporter declareReporter)
    {
        if (CollectionUtils.isNotEmpty(declareReporter.getDeclarationIdList())){
            for (int i = 0; i < declareReporter.getDeclarationIdList().size(); i++) {
                Long declarationId = declareReporter.getDeclarationIdList().get(i);
                DeclareReporter reporter = new DeclareReporter();
                BeanUtils.copyProperties(declareReporter,reporter);
                reporter.setDeclarationId(declarationId);
                reporter.setCreateTime(DateUtils.getNowDate());
                declareReporterMapper.insertDeclareReporter(reporter);
            }
            return declareReporter.getDeclarationIdList().size();
        }else {
            return 0;
        }
    }

    /**
     * 修改【请填写功能名称】
     * 
     * @param declareReporter 【请填写功能名称】
     * @return 结果
     */
    @Override
    public int updateDeclareReporter(DeclareReporter declareReporter)
    {
        declareReporter.setUpdateTime(DateUtils.getNowDate());
        return declareReporterMapper.updateDeclareReporter(declareReporter);
    }

    /**
     * 批量删除【请填写功能名称】
     * 
     * @param ids 需要删除的【请填写功能名称】ID
     * @return 结果
     */
    @Override
    public int deleteDeclareReporterByIds(Long[] ids)
    {
        return declareReporterMapper.deleteDeclareReporterByIds(ids);
    }

    /**
     * 删除【请填写功能名称】信息
     * 
     * @param id 【请填写功能名称】ID
     * @return 结果
     */
    @Override
    public int deleteDeclareReporterById(Long id)
    {
        return declareReporterMapper.deleteDeclareReporterById(id);
    }
}
